

package com.hex.ds.code.detection.config.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hex.ds.code.detection.config.model.RolesGit;
import com.hex.ds.code.detection.common.annotation.AnonymousAccess;
import org.springframework.http.ResponseEntity;
import com.hex.ds.code.detection.config.service.RolesGitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 权限与git中间表
 *
 * @author zl
 * @date 2024-02-26 16:21:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/rolesgit" )
@Api(value = "rolesgit", tags = "权限与git中间表管理")
public class RolesGitController {

    private final  RolesGitService rolesGitService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param rolesGit 权限与git中间表
     * WrapperEnhancer.like(rolesGit); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public ResponseEntity<Object> getRolesGitPage(Page page, RolesGit rolesGit) {
        return ResponseEntity.ok(rolesGitService.queryList(page,rolesGit));
    }


    //不分页通过roleId查
    @GetMapping("/id/{id}")
    @AnonymousAccess
    public ResponseEntity<Object> getRolesPublishuserNoPage(@PathVariable String id){
        return ResponseEntity.ok(rolesGitService.queryListNoPage(id));
    }

    /**
     * 通过id查询权限与git中间表
     * @param roleId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{roleId}" )
    public ResponseEntity<Object> getById(@PathVariable("roleId" ) String roleId) {
        return ResponseEntity.ok(rolesGitService.getById(roleId));
    }

    /**
     * 新增权限与git中间表
     * @param rolesGit 权限与git中间表
     * @return R
     */
    @ApiOperation(value = "新增权限与git中间表", notes = "新增权限与git中间表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody RolesGit rolesGit) {
        return ResponseEntity.ok(rolesGitService.save(rolesGit));
    }

    /**
     * 修改权限与git中间表
     * @param rolesGit 权限与git中间表
     * @return R
     */
    @ApiOperation(value = "修改权限与git中间表", notes = "修改权限与git中间表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody RolesGit rolesGit) {
        return ResponseEntity.ok(rolesGitService.updateById(rolesGit));
    }

    /**
     * 通过id删除权限与git中间表
     * @param roleId id
     * @return R
     */
    @ApiOperation(value = "通过id删除权限与git中间表", notes = "通过id删除权限与git中间表")
    @DeleteMapping("/{roleId}" )
    public ResponseEntity<Object> removeById(@PathVariable String roleId) {
        return ResponseEntity.ok(rolesGitService.removeById(roleId));
    }

}
